package com.lhn.netty.netty_demo.inboundhandlerandoutboudhhandler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * @author lhn
 * @date 2025/06/11 19:32
 * @since 1.0.0
 **/
public class MyServerHandler extends SimpleChannelInboundHandler <Long> {
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, Long aLong) throws Exception {
        System.out.println("从客户端" + channelHandlerContext.channel().remoteAddress() + " 读取到long: " + aLong);
        // 回复一个long
        channelHandlerContext.writeAndFlush(98765L);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }
}